
using Godot;
using System;
using Darksky.GodotAddons.GizmosDisplay;


[Tool]
public partial class CameraAreaConfig : Area2D
{
	[Export]
	public bool SetLimit { get; set; } = false;
	[Export]
	public bool SetFocus { get; set; } = false;
	[Export]
	public bool SetZoom { get; set; } = false;
	[Export]
	public bool SetOffset { get; set; } = false;

	[Export]
	public bool EnableLimitBox { get; set; } = false;
	[Export]
	public Rect2I LimitBox { get => _limitBox; set { _limitBox = value; UpdateGizmos(); } }
	private Rect2I _limitBox = default;

	[Export]
	public Node2D FocusNode { get; set; } = null;

	[Export]
	public float Zoom { get; set; } = 1.0f;

	[Export]
	public Vector2 Offset { get; set; } = Vector2.Zero;

	[Export]
	public bool ShowGizmosInGame { get; set; } = false;

	// Child node reference
	private RectGizmos _rectGizmos;

	// Running mode
	private bool _editorHint = false;

    public override void _Ready()
    {
		_editorHint = Engine.IsEditorHint();

		if (_editorHint || ShowGizmosInGame)
		{
			_rectGizmos = GetNode<RectGizmos>("./RectGizmos");
			_rectGizmos.DrawInGame = true;
			UpdateGizmos();
		}

		if (!_editorHint && FocusNode == null)
		{
			FocusNode = GetNode<NodeReferenceMap>(Constants.NodeRefMapPath).MainPlayer;
		}
    }

	public void UpdateGizmos()
	{
		if (_rectGizmos != null)
		{
            _rectGizmos.Rect = _limitBox;
        }
	}

}
